<?
function _skin_link($e,$furl="..") {
	if ($e["link"]) $uri = "$furl/{$e["link"]}";
	else $uri = "$furl/{$e["id"]}";
	if ($e["uri"]) $uri = $e["uri"];
	$href = " href='$uri' ";
	if ($e["target"]) $href.=" target='{$e["target"]}' ";
	return $href;
	}
	
function _skin_top($where) {
	global $db;
	return $db->query("select * from node where $where and hidden = 0 and parentid = 0 order by orders");
	}

function _skin_path($where,$id) {
	global $db;
	$r = array();
	while ($id) {
		$r[] = $e = $db->query1("select * from node where $where and id = ".$db->sqlint($id));
		$id = $e["parentid"];
		}
	return array_reverse($r);
	}


function _skin_tree($where,$ids) {
	global $db;
	
	$more = array();
	foreach ($ids as $id) foreach ($db->query("select * from node where $where and hidden = 0 and parentid = ".$db->sqlint($id)." order by orders") as $e) $more[$e["parentid"]][]=$e;
	
	$r = array();
	$top = array_shift($ids);
	if (!isset($more[$top])) return $r;
	
	$out=array_reverse($more[$top]);
	while (count($out)) {
        	$e=array_pop($out);
		$e["level"] = intval($e["level"]);
        	if (isset($more[$e["id"]])) {
			$a = array_reverse($more[$e["id"]]);
			foreach ($a as $k=>$ee) $a[$k]["level"] = $e["level"]+1;
			array_splice($out,count($out),0,$a);
			}
		$r[] = $e;
		}
	return $r;
	}

function _skin_tree_expanded($where) {
	global $db;
	
	$more = array();
	foreach ($db->query("select * from node where $where and hidden = 0 order by orders") as $e) $more[$e["parentid"]][]=$e;
	
	$r = array();
	$top = 0;#array_shift($ids);
	if (!isset($more[$top])) return $r;
	
	$out=array_reverse($more[$top]);
	while (count($out)) {
        	$e=array_pop($out);
		$e["level"] = intval($e["level"]);
        	if (isset($more[$e["id"]])) {
			$a = array_reverse($more[$e["id"]]);
			foreach ($a as $k=>$ee) $a[$k]["level"] = $e["level"]+1;
			array_splice($out,count($out),0,$a);
			}
		$r[] = $e;
		}
	return $r;
	}

	
function _skin_children($where,$id) {
	global $db;
	return $db->query("select * from node where $where and hidden = 0 and parentid = ".$db->sqlint($id)." order by orders");
	}
?>